<?php
namespace Home\Controller;
use Think\Controller;
class SmsController extends CommonController{
	function sms(){
		$user_name = session("user_name");
		$model = M("information");
		$count = $model->where("user_name='%s' and status=1", $user_name)->count();
		$this->ajaxReturn($count);
	}
	
	function smslist(){
		$user_name = session("user_name");
		$model = M("information");
		$count = $model->where("user_name='%s' and status=1", $user_name)->count();
		$page = new \Think\Page($count,C("PAGE_LIST_ROWS"));
		$show = $page->show();
		
		$data = $model->where("user_name='%s'", $user_name)->order("status desc, time desc")->limit($page->firstRow.','.$page->listRows)->select();
		$this->assign("data",$data);
		$this->assign("page",$show);
		$this->assign("empty", emptyhtml("list"));
		$this->display();
	}
	
	public function over(){
		$id = I('get.id');
		$id = trim($id, ",");
		if($id == ""){$this->ajaxReturn("请至少选择一项！");}
		$model = M("information");
		$user_name = session("user_name");
		$where = "user_name = '$user_name' and status = 1 and (";
		$id_arr = explode(",", $id);
		foreach ($id_arr as $value){
			$where .= "id=$value or ";
		}
		$where = substr($where, 0 , -4).")";
		$model->where($where)->setField("status", 0);
	}
	
	public function wait(){
		$id = I('get.id');
		$id = trim($id, ",");
		if($id == ""){$this->ajaxReturn("请至少选择一项！");}
		$model = M("information");
		$user_name = session("user_name");
		$where = "user_name = '$user_name' and status = 0 and (";
		$id_arr = explode(",", $id);
		foreach ($id_arr as $value){
			$where .= "id=$value or ";
		}
		$where = substr($where, 0 , -4).")";
		$model->where($where)->setField("status", 1);
	}
	
	public function delete(){
		$id = I('get.id');
		$id = trim($id, ",");
		if($id == ""){$this->ajaxReturn("请至少选择一项！");}
		$model = M("information");
		$user_name = session("user_name");
		$where = "user_name = '$user_name' and (";
		$id_arr = explode(",", $id);
		foreach ($id_arr as $value){
			$where .= "id=$value or ";
		}
		$where = substr($where, 0 , -4).")";
		$model->where($where)->delete();
	}
    
    public function _empty($name){
    	$this->emptyaction($name);
    }
}
?>